﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.DAL;

namespace FilStartUps
{
    public partial class NewThread : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                LinkButton lkHome = (LinkButton)FilStartUps_PageNav1.FindControl("lbLgout");
                LinkButton lkProfile = (LinkButton)FilStartUps_PageNav1.FindControl("lbProfile");
                lkProfile.Visible = true;
                lkHome.Visible = true;
            }
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {
                using (FilStartUpsEntities db_connect = new FilStartUpsEntities())
                {
                    ForumThread forum = new ForumThread();
                    var user = db_connect.Members
                                    .Where(m => m.emailaddress.Equals(User.Identity.Name))
                                        .SingleOrDefault();

                    forum.datecreated = DateTime.Now;
                    forum.forumdescription = txtmessage.Text;
                    forum.forumtitle = txttitle.Text;
                    forum.forumidFK = Convert.ToInt32(Request.QueryString["f"].Trim());
                    forum.memberidFK = user.memberidPK;
                    db_connect.ForumThreads.Add(forum);
                    db_connect.SaveChanges();
                    
                    Response.Redirect("~/ForumDisplay.aspx?f=" + Convert.ToInt32(Request.QueryString["f"].Trim()));
                }
            }
        }

        protected void CheckEditorNotEmptyServerSide(object sender, ServerValidateEventArgs args)
        {
            bool valid = args.Value.Length > 0;
            args.IsValid = valid;
        }


    }
}